package com.mi.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.Session;

import com.mi.bean.OrdersBean;
import com.mi.service.impl.AddGoodsService;
import com.mi.service.impl.AddOrderService;
import com.mi.utils.MyUtils;

/**
 *对订单表的响应处理
 */
@WebServlet("/AddOrdersAction")
public class AddOrdersAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 将购物车中的商品加入订单表中的请求处理
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 
		String goods_id = request.getSession().getAttribute("goods_id").toString();
		String customer_id =request.getSession().getAttribute("sid").toString();
		String counts=request.getSession().getAttribute("total").toString();
		System.out.println("获取的商品编号"+goods_id);
		System.out.println("获取的客户编号"+customer_id );
		System.out.println("获取的商品总额"+counts );
		OrdersBean ob=new OrdersBean();
		ob.setGoods_id(goods_id);
		ob.setCustomer_id(customer_id);
		ob.setCounts(counts);
		System.out.println(ob.toString());
		int i =MyUtils.getInstance(AddOrderService.class).add2Order(ob);
			
		if(i > 0) {
			// 请求成功
			// 对ajax请求进行响应
			PrintWriter pw = response.getWriter();
			// write方法写入字符串
			pw.write("加入订单成功！");
			pw.flush();
		}
		
	}

}
